using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;

namespace WorkFlowCore.BusinessDemo.Web.Controllers
{
    public class BaseController : Controller
    {
        protected ClaimsIdentity CurrentUser
        {
            get
            {
                // When using Cookie Authentication, the User.Identity should already be a ClaimsIdentity
                // if the user is authenticated.
                return User.Identity as ClaimsIdentity;
            }
        }

        protected string CurrentUserId => CurrentUser?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
        protected string CurrentUserName => CurrentUser?.FindFirst(ClaimTypes.Name)?.Value;
        protected string CurrentUserEmail => CurrentUser?.FindFirst(ClaimTypes.Email)?.Value;
        protected string CurrentEmployeeNumber => CurrentUser?.FindFirst("EmployeeNumber")?.Value;
    }
}
